
#import "WWButton.h"
#import "WWButtonCell.h"

#import "avoidStupidWarnings.h"

@implementation WWButton

static id myStoredCellClass;


+ initialize 
{ 
  [WWButton setVersion:1]; 

  if (self == [WWButton class])
  {  myStoredCellClass = [WWButtonCell class];
  }

  return self; 
}
//
+ setCellClass:classID
{
  myStoredCellClass = classID;
  return self;
}
////////////////////////////////////////////////////////
- initFrame:(const NXRect *)frameRect icon:(const char *)aString tag:(int)anInt target:anObject action:(SEL)aSelector key:(unsigned short)charCode enabled:(BOOL)flag
{
  id  oldCell;


  [super initFrame:frameRect icon:aString tag:anInt target:anObject action:aSelector key:charCode enabled:flag];
  oldCell = [self setCell:[[WWButtonCell alloc] init]];
  [oldCell free];
  return self;
}
//
- initFrame:(const NXRect *)frameRect title:(const char *)aString tag:(int)anInt target:anObject action:(SEL)aSelector key:(unsigned short)charCode enabled:(BOOL)flag
{
  id  oldCell;


  [super initFrame:frameRect title:aString tag:anInt target:anObject action:aSelector key:charCode enabled:flag];
  oldCell = [self setCell:[[myStoredCellClass alloc] init]];
  [oldCell free];
  return self;
}
//
- init
{
  id  oldCell;


  [super init];
  oldCell = [self setCell:[[myStoredCellClass alloc] init]];
  [oldCell free];
  return self;
}

// need to be able to see the cell's tclVar...
- setTclVar:(const char *)str { return [[self cell] setTclVar:str]; }
- (const char *)tclVar { return [[self cell] tclVar]; }

// need to be able to see the cell's controlString...
- setControlString:(const char *)str { return [[self cell] setControlString:str]; }
- (const char *)controlString { return [[self cell] controlString]; }

// need to be able to see the cell's tclExpression...
- setTclExpression:(const char *)str { return [[self cell] setTclExpression:str]; }
- (const char *)tclExpression { return [[self cell] tclExpression]; }

// need to be able to see the cell's tclExpression...
- setTclCommand:(const char *)str { return [[self cell] setTclCommand:str]; }
- (const char *)tclCommand { return [[self cell] tclCommand]; }

- setInterp:newInterp {  return [[self cell] setInterp:newInterp]; }
- evaluateSelf { return [[self cell] evaluateSelf]; }

- sendAction:(SEL)theAction to:theTarget
{
  if ([cell respondsTo:@selector(updateInterp)])
  {  [cell updateInterp];
  }

  return [super sendAction:theAction to:theTarget];
}

// IB stuff
- (const char *)getInspectorClassName 
{  
   NXEvent  *event = [NXApp currentEvent];

   if (event->flags & NX_ALTERNATEMASK)
   {  return [super getInspectorClassName];
   }
   
   return "WWButtonIBInspector"; 
}

- write:(NXTypedStream *)stream 
{
   [super write:stream];
   return self;
}
//
- read:(NXTypedStream *)stream 
{
   int version;

   [super read:stream];

   version = NXTypedStreamClassVersion(stream, "WWButton");
   if (version == 1)
   {  
   }
   return self;
}

@end
